package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.MasterBean;
import com.example.administrator.yuejian2.service.MasterDetailService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;
import static com.example.administrator.yuejian2.other.Url.URL4;

public class MasterDetailModel {
    private Retrofit retrofit;
    private MasterDetailService masterDetailService;
    public MasterDetailModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL4)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        masterDetailService=retrofit.create(MasterDetailService.class);
    }
    public void getMasterDetail(String master_id, final RetrofitListener listener)
    {
        Call<MasterBean> call=masterDetailService.masterdetail(master_id);
        call.enqueue(new Callback<MasterBean>() {
            @Override
            public void onResponse(Call<MasterBean> call, Response<MasterBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<MasterBean> call, Throwable t) {
                    listener.onFail();
            }
        });
    }
}
